<?php

require_once 'Zend/View/Helper/Abstract.php';

class Core_View_Helper_Admin_RenderBookmarks extends Zend_View_Helper_Abstract
{
    public function renderBookmarks($bookmarks = null)
    {
        $xhtml = '';
        if (!is_array($bookmarks)) {
            $mdlBookmark = new Model_Bookmark();
            $bookmarks = $mdlBookmark->getUsersBookmarks();
        }
        if (!empty($bookmarks)) {
            $xhtml = '<ul class="bookmarks">';
            foreach ($bookmarks as $bookmark) {
                $xhtml .= '    <li>' . PHP_EOL;
                $xhtml .= '        ' . $this->view->link(null, '/admin/index/delete-bookmark/id/' . $bookmark->id, 'link_delete.png', 'clear') . PHP_EOL;
                $url = $bookmark->url;
                if (strpos($url, 'mod_') === 0) {
                    $url = str_replace('mod_', '', $url);
                    $url = Core_Toolbox_String::stripUnderscores($url);
                    $url = 'mod_' . $url;
                } else {
                    $url = Core_Toolbox_String::stripUnderscores($url);
                }
                $xhtml .= '        ' . $this->view->link($bookmark->label, '/' . $url);
                $xhtml .= '    </li>';
            }
            $xhtml .= '</ul>';
        } else {
            $xhtml = $this->view->getTranslation('You do not have any bookmarks.');
        }
        return $xhtml;
    }
}